package edu.uclmgmu.bacteriosec.aspects.com.mysql.jdbc.PreparedStatement.setString;

//import com.mysql.jdbc.PreparedStatement;
import edu.uclmgmu.bacteriosec.aspects.common.Store;
import java.sql.PreparedStatement;

privileged aspect PreparedStatement_SetInverter {

	void around(java.sql.PreparedStatement caller, int col, String value) : target(caller) && args(col, value) && 
			call(* java.sql.PreparedStatement.setString(int, String)) {
		String currentJoinPoint = Store.getCurrentjoinPoint();
		String signature=thisJoinPointStaticPart.getSignature().toString();
		if (currentJoinPoint.equals(signature)) {
			int numberOfCallInTurn = Store.getNumberOfCallInTurn(signature);
			int numberOfCurrentCall = Store.getNumberOfCurrentCall(signature);
			if (numberOfCallInTurn == numberOfCurrentCall) {
				Store.updateNumberOfCurrentCall(signature);
				String auxi="";
				for (int i=value.length()-1; i>=0; i--)
					auxi+=value.charAt(i);
				proceed(caller, col, auxi);
			} else {
				Store.updateNumberOfCurrentCall(signature);
				proceed(caller, col, value);
			}
		} else {
			proceed(caller, col, value);
		}	
	}
}
